<?php
return [
    'module' => [
        'name' => 'article',
        'title' => '文章管理',
        'table' => 'articles',
    ],
    
    'fields' => [
        'id' => [
            'type' => 'int',
            'length' => 11,
            'comment' => '文章ID',
            'primary' => true,
            'auto_increment' => true,
            'nullable' => false,
            'required' => true,
        ],
        'title' => [
            'type' => 'varchar',
            'length' => 255,
            'comment' => '文章标题',
            'required' => true,
            'nullable' => false,
            'rules' => 'required',
        ],
        'slug' => [
            'type' => 'varchar',
            'length' => 255,
            'comment' => '文章标识',
            'required' => true,
            'nullable' => false,
            'rules' => 'required|unique:articles',
        ],
        'category_id' => [
            'type' => 'int',
            'length' => 11,
            'comment' => '分类ID',
            'required' => true,
            'nullable' => false,
            'rules' => 'required|exists:article_categories,id',
        ],
        'summary' => [
            'type' => 'varchar',
            'length' => 500,
            'comment' => '文章摘要',
            'required' => false,
            'nullable' => true,
        ],
        'content' => [
            'type' => 'text',
            'comment' => '文章内容',
            'required' => true,
            'nullable' => false,
        ],
        'thumbnail' => [
            'type' => 'varchar',
            'length' => 255,
            'comment' => '缩略图',
            'required' => false,
            'nullable' => true,
        ],
        'author_id' => [
            'type' => 'int',
            'length' => 11,
            'comment' => '作者ID',
            'required' => true,
            'nullable' => false,
        ],
        'view_count' => [
            'type' => 'int',
            'length' => 11,
            'comment' => '浏览次数',
            'default' => 0,
        ],
        'comment_count' => [
            'type' => 'int',
            'length' => 11,
            'comment' => '评论数量',
            'default' => 0,
        ],
        'is_top' => [
            'type' => 'tinyint',
            'length' => 1,
            'comment' => '是否置顶',
            'default' => 0,
            'options' => [
                0 => '否',
                1 => '是'
            ],
        ],
        'status' => [
            'type' => 'tinyint',
            'length' => 1,
            'comment' => '状态',
            'default' => 1,
            'options' => [
                0 => '草稿',
                1 => '发布',
                2 => '待审核'
            ],
        ],
        'published_at' => [
            'type' => 'timestamp',
            'comment' => '发布时间',
            'nullable' => true,
        ],
        'created_at' => [
            'type' => 'timestamp',
            'comment' => '创建时间',
            'nullable' => false,
            'default' => 'CURRENT_TIMESTAMP',
            'raw_default' => true
        ],
        'updated_at' => [
            'type' => 'timestamp',
            'comment' => '更新时间',
            'nullable' => false,
            'default' => 'CURRENT_TIMESTAMP',
            'raw_default' => true,
            'extra' => 'ON UPDATE CURRENT_TIMESTAMP'
        ],
    ],
    
    'relations' => [
        'category' => [
            'type' => 'belongsTo',
            'model' => 'ArticleCategory',
            'foreign_key' => 'category_id',
        ],
        'author' => [
            'type' => 'belongsTo',
            'model' => 'Admin',
            'foreign_key' => 'author_id',
        ],
        'tags' => [
            'type' => 'belongsToMany',
            'model' => 'ArticleTag',
            'table' => 'article_tag_relations',
            'foreign_key' => 'article_id',
            'other_key' => 'tag_id',
        ],
    ],
    
    'queries' => [
        'title' => ['like', '%?%'],
        'category_id' => ['=', '?'],
        'author_id' => ['=', '?'],
        'status' => ['=', '?'],
        'is_top' => ['=', '?'],
    ],
]; 